﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Admin.ProjectInfo
{
    public partial class ProjectLog : System.Web.UI.Page
    {
        ChinaSoft.Model.Model_tb_Midsoft_ProjectLog modelLog = new ChinaSoft.Model.Model_tb_Midsoft_ProjectLog();
        ChinaSoft.BLL.BLL_tb_Midsoft_ProjectLog bllLog = new ChinaSoft.BLL.BLL_tb_Midsoft_ProjectLog();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["ProjectId"] != null && Request.Params["ProjectId"].Trim() != "")
                {
                    int projectId = ChinaSoft.Common.Input.SetInt(Request.Params["ProjectId"]);
                    BindData();
                }
            }
        }

        #region gridView
        public void BindData()
        {
            #region
            //if (!Context.User.Identity.IsAuthenticated)
            //{
            //    return;
            //}
            //AccountsPrincipal user = new AccountsPrincipal(Context.User.Identity.Name);
            //if (user.HasPermissionID(PermId_Modify))
            //{
            //    gridView.Columns[6].Visible = true;
            //}
            //if (user.HasPermissionID(PermId_Delete))
            //{
            //    gridView.Columns[7].Visible = true;
            //}
            #endregion
            StringBuilder strWhere = new StringBuilder();
            if (Request.Params["ProjectId"] != null && Request.Params["ProjectId"].Trim() != "")
            {
                strWhere.AppendFormat(" and ProjectId={0}", Request.Params["ProjectId"]);
            }
            if (txtMinDate.Value != "" && txtMaxDate.Value != "")
                strWhere.AppendFormat(" and CreateTime between '" + txtMinDate.Value + "' and '" + txtMaxDate.Value + "'");
            else if (txtMinDate.Value != "" && txtMaxDate.Value == "")
                strWhere.AppendFormat(" and CreateTime>'" + txtMinDate.Value + "'");
            else if (txtMinDate.Value == "" && txtMaxDate.Value != "")
                strWhere.AppendFormat(" and CreateTime<'"+txtMaxDate.Value+"'");

            try
            {
                ChinaSoft.BLL.Common.Pager.BindGridView(gridView, AspNetPager1, "V_ProjectLog", "ProjectLogId", "*", strWhere.ToString(), "CreateTime desc", "");
            }
            catch (Exception ex)
            {
                Response.Write("数据库错误：" + ex.Message);
                Response.End();
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
        protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridView.PageIndex = e.NewPageIndex;
            BindData();
        }
        protected void gridView_OnRowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Text = "<input type=\"checkbox\" id=\"cbSelectAll\" name=\"cbSelectAll\" onclick=\"javascript:checkJs(this.checked);\" />";
            }
        }
        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //LinkButton linkbtnDel = (LinkButton)e.Row.FindControl("LinkButton1");
                //linkbtnDel.Attributes.Add("onclick", "return confirm(\"你确认要删除吗\")");

                //object obj1 = DataBinder.Eval(e.Row.DataItem, "Levels");
                //if ((obj1 != null) && ((obj1.ToString() != "")))
                //{
                //    e.Row.Cells[1].Text = obj1.ToString();
                //}

            }
        }
        protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //#warning 代码生成警告：请检查确认真实主键的名称和类型是否正确
            int ID = (int)gridView.DataKeys[e.RowIndex].Value;
            modelLog = bllLog.GetModel(ID);
            if (modelLog != null)
            {
                int createUserId = 0;
                if (Session["currentUserID"] != null && Session["currentUserID"].ToString() != "")
                    createUserId = ChinaSoft.Common.Input.SetInt(Session["currentUserID"]);

                    bllLog.Delete(ID);
            }
            else
                Maticsoft.Common.MessageBox.Show(this, "该日志以不存在！");
            BindData();
            //bll.Delete(ID);
            //gridView.OnBind();
        }
        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < gridView.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)gridView.Rows[i].FindControl("checkboxname");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (gridView.DataKeys[i].Value != null)
                    {
                        idlist += gridView.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
        #endregion

        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            BindData();
        }
    }
}